#include"PthreadPool.hpp"
#include<unistd.h>
#include<ctime>
#include"Log.hpp"
#include"LockGuard.hpp"
// #include<memory>


// void test1()//线程池执行任务
// {
//     srand(time(nullptr) ^ getpid() ^ pthread_self());
//     ThreadPool<Task> *tp = new ThreadPool<Task>(5);
//     std::cout << "here 1" << std::endl;
//     tp->Init();
//     tp->Start();
//     int time = 0;
//     while (true)
//     {
//         //推送任务
//         int a = rand() % 100 + 1;
//         int b = rand() % 50 + 1;
//         Task t(a, b);
//         tp->Equeue(t);
//         sleep(1);
//         time += 1;
//         if(time % 3 ==0)
//         std::cout << "time:" << time <<",now here are "<< tp->TaskNum()<<" tasks to deal" << std::endl;
//     }
// }
void test2()//测试日志系统
{
    std::cout << GetCurrTime() << std::endl;
    Log lg;
    lg.Enable(FILE_TYPE);
     lg.logMessage(__FILE__, __LINE__,DEBUG,"hello %04d ,my world is %s\n", 14, "blue");
     lg.logMessage(__FILE__, __LINE__,INFO,"hello %04d ,my world is %s\n", 43, "yellow");
     lg.logMessage(__FILE__, __LINE__,ERROR,"hello %04d ,my world is %s\n", 5, "red");
     lg.logMessage(__FILE__, __LINE__,FATAL,"hello %04d ,my world is %s\n", 1, "for you");

    //LOG(DEBUG, "hello %04d ,my world is %s\n", 5, "red");
    //LOG(DEBUG, "hello 00510 ,my world is blue\n");

}
//单例模式
void test3()
{
    srand(time(nullptr) ^ getpid() ^ pthread_self());
    ThreadPool<Task>::getInstance();
    int time = 0;
    while (true)
    {
        //推送任务
        int a = rand() % 100 + 1;
        int b = rand() % 50 + 1;
        Task t(a, b);
        ThreadPool<Task>::getInstance()->Equeue(t);
        sleep(1);
        time += 1;
        if(time % 3 ==0)
        std::cout << "time:" << time <<",now here are "<< ThreadPool<Task>::getInstance()->TaskNum()<<" tasks to deal" << std::endl;
    }
}
int main()
{
    test3();
}